package main

import "fmt"
import "errors"

type argError struct {
	arg  int
	prob string
}

func (e *argError) Error() string {
	return fmt.Sprintf("%d - %s", e.arg, e.prob)
}

func f1(arg int) (int, error) {
	if arg == 2 {
		return 2, errors.New("can't work with 2")
	}

	return arg + 3, nil
}

func f2(arg int) (int, error) {
	if arg == 3 {
		return 3, &argError{arg, "Can't work with 3"}
	}
	return arg + 3, nil
}

func main16() {
	for _, i := range []int{1, 2, 3} {
		val, e := f1(i)
		if e != nil {
			fmt.Println(e)
		} else {
			fmt.Println(val)
		}
	}

	for _, i := range []int{1, 2, 3} {
		if v, ok := f2(i); ok != nil {
			fmt.Println(ok)
		} else {
			fmt.Println(v)
		}
	}

	_, e := f2(3)
	if ae, ok := e.(*argError); ok {
		fmt.Println(ae.arg)
		fmt.Println(ae.prob)
	}
}
